package cn.chengpengper.im.platform.common.interceptor.base;

import cn.chengpengper.im.platform.common.risk.rule.service.RuleChainService;
import org.apache.commons.collections.CollectionUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.servlet.HandlerInterceptor;

import java.util.Collections;
import java.util.Comparator;
import java.util.List;
import java.util.stream.Collectors;
/*@formatter:off*/

/**
 * ____________________
 * < 神兽护体，永无bug! >
 * --------------------
 *
 * @author huchengpeng
 * @version v1.0.0
 * @date 2024/11/23 18:44
 * @description 基础拦截器
 */

/*@formatter:on*/

public abstract class BaseInterceptor implements HandlerInterceptor {

    @Autowired
    private List<RuleChainService> ruleChainServiceList;

    protected List<RuleChainService> getRuleChainServiceList() {
        if (CollectionUtils.isEmpty(ruleChainServiceList)) {
            return Collections.emptyList();
        }
        return ruleChainServiceList.stream().sorted(Comparator.comparing(RuleChainService::getOrder)).collect(Collectors.toList());
    }
}
